package com.ysstech.kettle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ysstech.common.entity.PageBean;
import com.ysstech.kettle.entity.JobDuties;
import com.ysstech.kettle.mapper.JobDutiesMapper;
import com.ysstech.kettle.service.JobDutiesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 采集任务信息表 服务实现类
 * </p>
 *
 * @author lishuangliang
 * @since 2022-10-25
 */
@Service
public class JobDutiesServiceImpl extends ServiceImpl<JobDutiesMapper, JobDuties> implements JobDutiesService {


    /**
     * 查询采集任务表列表信息
     *
     * @param jobDuties
     * @param pageBean
     * @return
     * @throws Exception
     */
    public PageBean<JobDuties> queryAllJobDuties(JobDuties jobDuties, PageBean pageBean) throws Exception {
        QueryWrapper<JobDuties> wrapper = this.getQueryWrapper(jobDuties);
        IPage pageBalance = this.page(new Page<>(pageBean.getPageNum(), pageBean.getPageSize()), wrapper);
        this.switchedListCategory(pageBalance.getRecords());
        return new PageBean<>(pageBalance);
    }


    /**
     * 类型，机构等中文的转换
     *
     * @param list
     * @return
     * @throws Exception
     */
    public List<JobDuties> switchedListCategory(List<JobDuties> list) throws Exception {
        for (JobDuties jobDuties : list) {
            if (null == jobDuties) {
                continue;
            }
        }
        return list;
    }

    /**
     * 查询条件
     *
     * @param jobDuties
     * @return
     * @throws Exception
     */
    private QueryWrapper<JobDuties> getQueryWrapper(JobDuties jobDuties) throws Exception {
        QueryWrapper<JobDuties> wrapper = new QueryWrapper<>();
        if (null == jobDuties) {
            return wrapper;
        }
        wrapper.orderByAsc("SEQUENCE");
        return wrapper;
    }
}
